package org.uiot.process

import org.apache.commons.collections.list.UnmodifiableList
import org.apache.flink.test.util.AbstractTestBase
import org.uiot.protocol.CachedCommandPacket
import org.uiot.protocol.CachedDataPacket
import org.uiot.protocol.PacketTraits
import org.uiot.protocol.codec.CachedRule
import org.uiot.protocol.codec.CodecTraits
import org.uiot.protocol.group.CachedSequence
import org.uiot.protocol.group.Groupable
import org.uiot.protocol.group.Subjection

class CodecTestBase extends AbstractTestBase {

    protected static final List<PacketTraits> packetTraits = [
            new CachedCommandPacket(1, "auth", PacketTraits.Direction.Upstream, new PacketTraits.BodyGroupType(request: Groupable.Type.Sequence, response: Groupable.Type.Sequence)),
            new CachedDataPacket(4, "location", PacketTraits.Direction.Upstream, new PacketTraits.BodyGroupType(request: Groupable.Type.Sequence, response: Groupable.Type.Sequence))
    ] as UnmodifiableList

    protected static final List<CachedRule> codecTraits = [
            new CachedRule(
                    code: "dataId", name: "数据封包标识", endian: CodecTraits.ENDIAN.LITTLE, length: 1,
                    lengthUnit: CodecTraits.LengthUnit.Byte, type: CodecTraits.Type.Numeric,
                    encodingScript: null, decodingScript: null, placeholder: null),
            new CachedRule(
                    code: "deviceId", name: "设备标识", endian: CodecTraits.ENDIAN.LITTLE, length: 10,
                    lengthUnit: CodecTraits.LengthUnit.Byte, type: CodecTraits.Type.StringASCII,
                    encodingScript: null, decodingScript: null, placeholder: null),
            new CachedRule(
                    code: "bcdDate", name: "编解码压缩BCD码格式的日期", endian: CodecTraits.ENDIAN.LITTLE, length: 6,
                    lengthUnit: CodecTraits.LengthUnit.Byte, type: CodecTraits.Type.StringCompressedBCD,
                    encodingScript: "x.format('yyMMddHHmmss')",
                    decodingScript: "new java.text.SimpleDateFormat('yyMMddHHmmss').parse(x)",
                    placeholder: null)
    ] as UnmodifiableList

    protected static final List<CachedSequence> sequenceTraits = [
//            new CachedSequence(part: PacketTraits.Part.Header, parentType: Subjection.Packet, parentCode: 01, serialNo: 1, name: "数据封包标识", dataIdentifier: "packetId", ruleCode: "packetId"),
//            new CachedSequence(part: PacketTraits.Part.Header, parentType: Subjection.Packet, parentCode: 01, serialNo: 3, name: "设备标识", dataIdentifier: "deviceId", ruleCode: "deviceId"),
//            new CachedSequence(part: PacketTraits.Part.Header, parentType: Subjection.Packet, parentCode: 01, serialNo: 5, name: "封包日期", dataIdentifier: "dataTimed", ruleCode: "bcdDate"),
            new CachedSequence(part: PacketTraits.Part.Body, parentType: Subjection.Packet, parentCode: 01, serialNo: 1, name: "数据封包标识", dataIdentifier: "dataId", ruleCode: "dataId"),
            new CachedSequence(part: PacketTraits.Part.Body, parentType: Subjection.Packet, parentCode: 01, serialNo: 3, name: "设备标识", dataIdentifier: "deviceId", ruleCode: "deviceId"),
            new CachedSequence(part: PacketTraits.Part.Body, parentType: Subjection.Packet, parentCode: 01, serialNo: 5, name: "封包日期", dataIdentifier: "dataTimed", ruleCode: "bcdDate")
    ] as UnmodifiableList
}
